package com.fenxiangtech.mall.manager;

import com.fenxiangtech.mall.dao.ProductPropertyDAO;
import com.fenxiangtech.mall.model.ProductProperty;
import com.fenxiangtech.mall.model.qc.ProductPropertyQC;
import com.fenxiangtech.mall.model.qc.Page;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

@Component
public class ProductPropertyManager {

    @Autowired
    private ProductPropertyDAO productPropertyDAO;

    public List<ProductProperty> queryProductProperty(ProductProperty productProperty, Integer pageIndex , Integer pageSize){
        Page page = new Page(pageIndex,pageSize);
        ProductPropertyQC qc  = new ProductPropertyQC();
        qc.setPage(page);
        BeanUtils.copyProperties(productProperty,qc);
        List<ProductProperty> productPropertys = productPropertyDAO.listProductProperty(qc);
        return productPropertys;
    }

    public Long countProductProperty(ProductProperty productProperty){
        ProductPropertyQC qc  = new ProductPropertyQC();
        BeanUtils.copyProperties(productProperty,qc);
        Long count = productPropertyDAO.countProductProperty(qc);
        return count;
    }

    public int saveProductProperty(ProductProperty productProperty){

        if(productProperty.getId()!=null){
            return productPropertyDAO.updateProductProperty(productProperty);
        }else {
            productProperty.setCreateTime(new Date());
            return productPropertyDAO.insertProductProperty(productProperty);
        }

    }
    public int deleteProductProperty(Long id){

        return productPropertyDAO.deleteProductPropertyById(id);

    }



}
